package com.dgut.shopManage.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dgut.common.util.ExtAjaxResponse;
import com.dgut.common.util.ExtPageable;
import com.dgut.shopManage.entity.Shop;
import com.dgut.shopManage.entity.dto.ShopDTO;
import com.dgut.shopManage.entity.dto.ShopQueryDTO;
import com.dgut.shopManage.service.IShopService;


@Controller
@RequestMapping("/shop")
public class ShopContreller {
	@Autowired
	private IShopService shopService;

	@RequestMapping("/shopSaveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(Shop shop) 
	{
		try {
			System.out.println("con:"+shop);
			shopService.saveOrUpdate(shop);
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
		
	}
	@RequestMapping("/shopDelete")
	public @ResponseBody ExtAjaxResponse delete(@RequestParam Long id) 
	{
		try {
			Shop shop =  shopService.findOne(id);
			if(null!=shop) {
				shopService.delete(shop);
			}
			return new ExtAjaxResponse(true,"操作成功！");
			}
			catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
			}
	}
	
	@RequestMapping("/shopFindOne")
	public @ResponseBody Shop findOne(@RequestParam Long id) 
	{
		Shop shop =  shopService.findOne(id);
		
		return shop;
	}
	
	
	@RequestMapping("/shopFindAll")
	public @ResponseBody List<Shop> findAll() 
	{
		 List<Shop> lists = shopService.findAll();
		
		return lists;
	}
	
	/*@RequestMapping("/shopFindPage")
	public @ResponseBody Page<Shop> findPage(ShopQueryDTO shopQueryDTO,ExtPageable pageable) 
	{
		Page<Shop> page =  shopService.findAll(shopQueryDTO.getSpecification(shopQueryDTO), pageable.getPageable());
		return page;
	}*/
	
	@RequestMapping("/shopFindPage")
	public @ResponseBody Page<ShopDTO> findPage(ShopQueryDTO shopQueryDTO,ExtPageable pageable) 
	{
		Page<ShopDTO> page =  shopService.findAll(shopQueryDTO.getSpecification(shopQueryDTO), pageable.getPageable());
		return page;
	}
	@RequestMapping("/shopFindPage2")
	public @ResponseBody Page<ShopDTO> findPage2(ShopQueryDTO shopQueryDTO,ExtPageable pageable) 
	{
		Page<ShopDTO> page =  shopService.findAll(shopQueryDTO.getSpecification(shopQueryDTO), pageable.getPageable());
		return page;
	}
}
